package com.powernode.controller;


import com.powernode.service.UmsResourceService;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.powernode.common.ResultJson;
import com.powernode.entity.UmsRoleResource;
import com.powernode.service.UmsRoleResourceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色关联资源 前端控制器
 * </p>
 *
 * @author lxl
 * @since 2022-04-11
 */
@RestController
@RequestMapping("/umsRoleResource")
public class UmsRoleResourceController {
    @Resource
    private UmsRoleResourceService umsRoleResourceService;

    @Resource
    private UmsResourceService umsResourceService;

    @GetMapping("/getData")
    ResultJson<Map<String, List>> getData(Long roleId){
        Map<String, List> map = new HashMap<String, List>();

        map.put("resource",umsResourceService.getAll());
        map.put("values",umsRoleResourceService.getByRoleId(roleId));
        return ResultJson.success(map);
    }

    @PostMapping("/save")
    ResultJson save(Long roleId,Long[] menus,Long[] btns){
        return ResultJson.success(umsRoleResourceService.save(roleId,menus,btns),"关联资源成功");
    }
}
